#include "head.h"
#include <iostream>

using std::cout;
using std::endl;

void test0()
{
    const char * addr = "192.168.30.129";
    struct in_addr naddr;//网络字节序的IP地址
    inet_aton(addr, &naddr);
    printf("naddr: %p\n", naddr.s_addr);

    //将网络字节序的IP地址转换成字符串形式的
    char * p = inet_ntoa(naddr);
    printf("p: %s\n", p);
}

void test1()
{
    struct sockaddr addr;//这是一个基类
    struct sockaddr_in saddr;//这是一个派生类
    printf("sizeof(addr): %d\n", sizeof(addr));
    printf("sizeof(saddr): %d\n", sizeof(saddr));

    memset(&saddr, 0, sizeof(saddr));//初始化服务器的网络地址
    saddr.sin_family = AF_INET;//IPV4类型
    saddr.sin_port = htons(8888);
    saddr.sin_addr.s_addr = inet_addr("192.168.30.129");
}

int main()
{
    /* test0(); */
    test1();
    return 0;
}

